package _22define.test;

import java.io.*;

public class work4 {
    public static void main(String[] args) throws IOException {
        File dir=new File("E:\\deleteexercise");
        String ab="E:\\deleteexercise3";
        if (copyAllJava(dir,ab)){
            System.out.println("复制成功");
        }
    }
    public static boolean copyAllJava(File dir,String ab) throws IOException {
        if (dir==null||!dir.exists()){
            return false;
        }
        File[] files=dir.listFiles();
        for (File file : files) {
            if (file.isFile()) {
                if (file.getName().endsWith(".java")) {
                    FileInputStream in = new FileInputStream(file.getPath());
                    FileOutputStream out = new FileOutputStream(ab + "\\" + file.getName());
                    int readData;
                    while ((readData=in.read())!=-1){
                        out.write(readData);
                    }
                    in.close();
                    out.flush();
                    out.close();
                }
            }else copyAllJava(file,ab);
        }
        return true;
    }
}
